package fnord.network.server;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import fnord.illuminati.card.ActionTime;
import fnord.illuminati.card.Alignment;
import fnord.illuminati.card.Connection;
import fnord.illuminati.card.GroupCard;
import fnord.illuminati.card.IlluminatiCard;
import fnord.illuminati.card.groupcards.TestGroupCard;
import fnord.illuminati.card.illuminaticards.TestIlluminatiCard;
import fnord.illuminati.order.MoneyTransferOrder;
import fnord.illuminati.order.TreeTransferOrder;

public class RefereeTests {
	
	private Player _player1, _player2;
	private Referee _ref;
	

	@Before
	public void setUp() throws Exception {
		IlluminatiCard player1card = new TestIlluminatiCard("Player1Card", "THIS IS A CARD", null, ActionTime.NEVER, 10, 10, 12, 0, null, null);
		_player1 = new Player(player1card);
		IlluminatiCard player2card = new TestIlluminatiCard("Player2Card", "THIS IS A CARD", null, ActionTime.NEVER, 10, 10, 12, 0, null, null);
		_player2 = new Player(player2card);
		Alignment[] card1Alig = {Alignment.COMMUNIST, Alignment.CONSERVATIVE};
		Connection[] card1Con = {Connection.NORTH, Connection.EAST};
		player2card.addCard(new TestGroupCard("GropuCard1", "THIS CARD GROPES THINGS IN JAPAN", null, ActionTime.NEVER, 3, 0, 5, 2, 0, card1Alig, card1Con), Connection.EAST);
		_ref = new Referee(null);
		_ref.addPlayer(_player1);
		_ref.addPlayer(_player2);
	}

	@After
	public void tearDown() throws Exception {
		_player1 = null;
		_player2 = null;
		_ref = null;
	}


	@Test
	public void testEnactTurn() {
		fail("Not yet implemented"); // TODO
	}

	@Test
	public void testDoUpkeep() {
		fail("Not yet implemented"); // TODO
	}

	@Test
	public void testDoIncome() {
		_ref.doIncome(_player2);
		assertEquals(_player2.getIlluminati().getMoney(), 12);
		assertEquals(_player2.getIlluminati().getChild(Connection.EAST).getMoney(), 2);
	}

	@Test
	public void testDoAttack() {
		fail("Not yet implemented"); // TODO
	}

	@Test
	public void testDoMoneyTransfer() {
		_ref.doIncome(_player2);
		MoneyTransferOrder mto = new MoneyTransferOrder(_player2, _player2.getIlluminati(), _player2.getIlluminati().getChild(Connection.EAST), 4);
		_ref.doMoneyTransfer(mto);
		assertEquals(_player2.getIlluminati().getMoney(), 8);
		assertEquals(_player2.getIlluminati().getChild(Connection.EAST).getMoney(), 6);
	}

	@Test
	public void testDoSpendMoney() {
		fail("Not yet implemented"); // TODO
	}

	@Test
	public void testDoTreeTransfer() {
		GroupCard transfering = _player2.getIlluminati().getChild(Connection.EAST);
		TreeTransferOrder tto = new TreeTransferOrder(_player2, _player2.getIlluminati().getChild(Connection.EAST), _player2.getIlluminati(), Connection.WEST);
		_ref.doTreeTransfer(tto);
		assertNull(_player2.getIlluminati().getChild(Connection.EAST));
		assertEquals(_player2.getIlluminati().getChild(Connection.WEST), transfering);
	}

	@Test
	public void testCheckWinConditions() {
		fail("Not yet implemented"); // TODO
	}

}
